<?php

namespace App\Service\GuildManage;

use App\Constants\ErrorCode;
use App\Exception\ApiException;
use App\Model\GuildManage\GuildAccount;
use App\Service\BaseService;
use App\Service\ServiceTrait\GuildTrait;

class DelService extends BaseService
{
    use GuildTrait;

    public function handle()
    {
        $userId = $this->getUserId();

        if (!$this->checkGuildStatus($userId)) {
            throw new ApiException('亲,暂时没有此操作权限哦!', ErrorCode::DEFAULT_ERROR);
        }

        $accountId = $this->request->input('account_id');

        $this->checkAccount($accountId, $userId);

        $guildAccountModel = new GuildAccount();
        if (!$guildAccountModel->where('id', $accountId)->delete()) {
            throw new ApiException('删除提现账号失败');
        }

        return ['msg' => '删除成功'];
    }
}